public class InterruptSynchronizedDemo {

    private static Object lock = new Object();//monitor
    private static class A extends Thread {
        @Override
        public void run() {
            //等待lock锁
            System.out.println("线程A等待lock");
            synchronized (lock) {
                System.out.println("线程A获取到锁");
                //等待标志位被置为true
                //while (!Thread.currentThread().isInterrupted()) {
                    System.out.println(Thread.currentThread().isInterrupted());
                //}
            }
            System.out.println("exit");
        }
    }

    public static void test() throws InterruptedException {
        synchronized (lock) {//获取锁
            System.out.println("main获取到lock");
            A a = new A();
            a.start();
            Thread.sleep(1000);
            //a在等待lock锁，interrupt 无法中断
            System.out.println("线程A设置为中断");
            a.interrupt();
            //a线程加入当前线程，等待执行完毕
            a.join();
            System.out.println("main结束,释放锁");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        test();
    }

}